home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / CGI / Switch.pm < prev   
Encoding:
Perl POD Document  |  1999-12-28  |  1.2 KB  |  71 lines

  1. package CGI::Switch;
  2. use Carp;
  3. use strict;
  4. use vars qw($VERSION @Pref);
  5. $VERSION = '0.05';
  6. @Pref = qw(CGI::Apache CGI); #default
  7.  
  8. sub import {
  9.     my($self,@arg) = @_;
  10.     @Pref = @arg if @arg;
  11. }
  12.  
  13. sub new {
  14.     shift;
  15.     my($file,$pack);
  16.     for $pack (@Pref) {
  17.     ($file = $pack) =~ s|::|/|g;
  18.     eval { require "$file.pm"; };
  19.     if ($@) {
  20.         next;
  21.     } else {
  22.         my $obj;
  23.         eval {$obj = $pack->new(@_)};
  24.         if ($@) {
  25.         } else {
  26.         return $obj;
  27.         }
  28.     }
  29.     }
  30.     Carp::croak "Couldn't load+construct any of @Pref\n";
  31. }
  32.  
  33. sub isaCGI { 1 }
  34.  
  35. 1;
  36. __END__
  37.  
  38. =head1 NAME
  39.  
  40. CGI::Switch - Try more than one constructors and return the first object available
  41.  
  42. =head1 SYNOPSIS
  43.  
  44.  
  45.  use CGISwitch;
  46.  
  47.   -or-
  48.  
  49.  use CGI::Switch This, That, CGI::XA, Foo, Bar, CGI;
  50.  
  51.  my $q = new CGI::Switch;
  52.  
  53. =head1 DESCRIPTION
  54.  
  55. Per default the new() method tries to call new() in the three packages
  56. Apache::CGI, CGI::XA, and CGI. It returns the first CGI object it
  57. succeeds with.
  58.  
  59. The import method allows you to set up the default order of the
  60. modules to be tested.
  61.  
  62. =head1 SEE ALSO
  63.  
  64. perl(1), Apache(3), CGI(3), CGI::XA(3)
  65.  
  66. =head1 AUTHOR
  67.  
  68. Andreas K÷nig E<lt>a.koenig@mind.deE<gt>
  69.  
  70. =cut
  71.